{% set pypi_name = 'horizon' %}
{% set source = fetch_source('https://tarballs.openstack.org/horizon/horizon-master.tar.gz') %}
{% set upstream_version = upstream_version() %}
{% set rpm_release = '1' %}

%if 0%{?rhel} || 0%{?fedora}
%global rdo 1
%global http_dashboard_dir %{_datarootdir}/openstack-dashboard
%else
%global http_dashboard_dir /srv/www/openstack-dashboard
%endif
Name:           {{ py2name() }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Epoch:          {{ epoch('horizon') }}
Summary:        OpenStack Dashboard (Horizon)
License:        {{ license('Apache-2.0') }}
Group:          Development/Languages/Python
URL:            https://docs.openstack.org/{{ pypi_name }}
Source0:        {{ source|basename }}
# https://review.openstack.org/#/c/635159/
Patch0:         0001-Do-not-set-COMPRESS_ENABLED-explicitly.patch
BuildRequires:  fdupes
BuildRequires:  gettext
BuildRequires:  openstack-macros
BuildRequires:  {{ py3('Django') }}
BuildRequires:  {{ py3('Pint') }}
BuildRequires:  {{ py3('XStatic') }}
BuildRequires:  {{ py3('XStatic-Angular') }}
BuildRequires:  {{ py3('XStatic-Angular-Bootstrap') }}
BuildRequires:  {{ py3('XStatic-Angular-FileUpload') }}
BuildRequires:  {{ py3('XStatic-Angular-Gettext') }}
BuildRequires:  {{ py3('XStatic-Angular-Schema-Form') }}
BuildRequires:  {{ py3('XStatic-Angular-lrdragndrop') }}
BuildRequires:  {{ py3('XStatic-Bootstrap-Datepicker') }}
BuildRequires:  {{ py3('XStatic-Bootstrap-SCSS') }}
BuildRequires:  {{ py3('XStatic-D3') }}
BuildRequires:  {{ py3('XStatic-Font-Awesome') }}
BuildRequires:  {{ py3('XStatic-Hogan') }}
BuildRequires:  {{ py3('XStatic-JQuery-Migrate') }}
BuildRequires:  {{ py3('XStatic-JQuery.TableSorter') }}
BuildRequires:  {{ py3('XStatic-JQuery.quicksearch') }}
BuildRequires:  {{ py3('XStatic-JSEncrypt') }}
BuildRequires:  {{ py3('XStatic-Jasmine') }}
BuildRequires:  {{ py3('XStatic-Rickshaw') }}
BuildRequires:  {{ py3('XStatic-Spin') }}
BuildRequires:  {{ py3('XStatic-bootswatch') }}
BuildRequires:  {{ py3('XStatic-jQuery') }}
BuildRequires:  {{ py3('XStatic-jquery-ui') }}
BuildRequires:  {{ py3('XStatic-mdi') }}
BuildRequires:  {{ py3('XStatic-objectpath') }}
BuildRequires:  {{ py3('XStatic-roboto-fontface') }}
BuildRequires:  {{ py3('XStatic-smart-table') }}
BuildRequires:  {{ py3('XStatic-term.js') }}
BuildRequires:  {{ py3('XStatic-tv4') }}
BuildRequires:  {{ py3('python-cinderclient') }}
BuildRequires:  {{ py3('devel') }}
BuildRequires:  {{ py3('django-compressor') }}
BuildRequires:  {{ py3('django-debreach') }}
BuildRequires:  {{ py3('django-pyscss') }}
BuildRequires:  {{ py3('python-glanceclient') }}
BuildRequires:  {{ py3('python-heatclient') }}
BuildRequires:  {{ py3('python-keystoneclient') }}
BuildRequires:  {{ py3('mock') }}
BuildRequires:  {{ py3('netaddr') }}
BuildRequires:  {{ py3('python-neutronclient') }}
BuildRequires:  {{ py3('python-novaclient') }}
BuildRequires:  {{ py3('oslo.concurrency') }}
BuildRequires:  {{ py3('oslo.policy') }}
BuildRequires:  {{ py3('osprofiler') }}
BuildRequires:  {{ py3('pbr') }}
BuildRequires:  {{ py3('pytest') }}
BuildRequires:  {{ py3('python-swiftclient') }}
BuildRequires:  {{ py3('testtools') }}
Requires:       python3-horizon = %{epoch}:%{version}-%{release}
Requires:       python3-openstack_auth = %{epoch}:%{version}-%{release}
Provides:       openstack-{{ pypi_name }} = %{version}-%{release}
BuildArch:      noarch
%if 0%{?suse_version}
BuildRequires:  apache2
Requires:       apache2
Requires:       apache2-mod_wsgi-python3
%endif
%if 0%{?rdo}
Requires:       httpd
Requires:       python3-mod_wsgi
%endif
# Apache2 example configuration:
%if 0%{?rdo}
Source2:        openstack-dashboard.conf.sample.rdo
%else
Source2:        openstack-dashboard.conf.sample.suse
%endif
# To generate a self-signed certificate to be used in demo setups:
%if 0%{?suse_version}
Requires(post):  apache2-utils
%endif
%if 0%{?rdo}
Requires(post):  httpd-tools
%endif

%description
The OpenStack dashboard provides administrators and users a graphical
interface to access, provision and automate cloud-based resources. The
extensible design makes it easy to plug in and expose third party
products and services, such as billing, monitoring and additional
management tools.

The dashboard is just one way to interact with OpenStack resources.
Developers can automate access or build tools to manage their resources
using the native OpenStack API or the EC2 compatibility API.

%package -n python3-horizon
Summary:        OpenStack Dashboard (Horizon) - Python Module
Group:          Development/Languages/Python
Requires:       {{ py3('Babel') }}
Requires:       {{ py3('Django') }}
Requires:       {{ py3('Pint') }}
Requires:       {{ py3('PyYAML') }}
Requires:       {{ py3('XStatic') }}
Requires:       {{ py3('XStatic-Angular') }}
Requires:       {{ py3('XStatic-Angular-Bootstrap') }}
Requires:       {{ py3('XStatic-Angular-FileUpload') }}
Requires:       {{ py3('XStatic-Angular-Gettext') }}
Requires:       {{ py3('XStatic-Angular-Schema-Form') }}
Requires:       {{ py3('XStatic-Angular-lrdragndrop') }}
Requires:       {{ py3('XStatic-Bootstrap-Datepicker') }}
Requires:       {{ py3('XStatic-Bootstrap-SCSS') }}
Requires:       {{ py3('XStatic-D3') }}
Requires:       {{ py3('XStatic-Font-Awesome') }}
Requires:       {{ py3('XStatic-Hogan') }}
Requires:       {{ py3('XStatic-JQuery-Migrate') }}
Requires:       {{ py3('XStatic-JQuery.TableSorter') }}
Requires:       {{ py3('XStatic-JQuery.quicksearch') }}
Requires:       {{ py3('XStatic-JSEncrypt') }}
Requires:       {{ py3('XStatic-Jasmine') }}
Requires:       {{ py3('XStatic-Rickshaw') }}
Requires:       {{ py3('XStatic-Spin') }}
Requires:       {{ py3('XStatic-bootswatch') }}
Requires:       {{ py3('XStatic-jQuery') }}
Requires:       {{ py3('XStatic-jquery-ui') }}
Requires:       {{ py3('XStatic-mdi') }}
Requires:       {{ py3('XStatic-objectpath') }}
Requires:       {{ py3('XStatic-roboto-fontface') }}
Requires:       {{ py3('XStatic-smart-table') }}
Requires:       {{ py3('XStatic-term.js') }}
Requires:       {{ py3('XStatic-tv4') }}
Requires:       {{ py3('python-cinderclient') }}
Requires:       {{ py3('django-babel') }}
Requires:       {{ py3('django-compressor') }}
Requires:       {{ py3('django-debreach') }}
Requires:       {{ py3('django-pyscss') }}
Requires:       {{ py3('futurist') }}
Requires:       {{ py3('python-glanceclient') }}
Requires:       {{ py3('python-heatclient') }}
Requires:       {{ py3('httplib2') }}
Requires:       {{ py3('iso8601') }}
Requires:       {{ py3('python-keystoneclient') }}
Requires:       {{ py3('netaddr') }}
Requires:       {{ py3('python-neutronclient') }}
Requires:       {{ py3('python-novaclient') }}
Requires:       {{ py3('oslo.concurrency') }}
Requires:       {{ py3('oslo.config') }}
Requires:       {{ py3('oslo.i18n') }}
Requires:       {{ py3('oslo.policy') }}
Requires:       {{ py3('oslo.serialization') }}
Requires:       {{ py3('oslo.utils') }}
Requires:       {{ py3('osprofiler') }}
Requires:       {{ py3('pbr') }}
Requires:       {{ py3('pyScss') }}
Requires:       {{ py3('pytz') }}
Requires:       {{ py3('semantic_version') }}
Requires:       {{ py3('six') }}
Requires:       {{ py3('python-swiftclient') }}

%description -n python3-horizon
The Python module horizon is the core component of the OpenStack
dashboard.

%package -n python3-openstack_auth
Summary:        OpenStack Auth (Horizon) - Python Module
Group:          Development/Languages/Python

%description -n python3-openstack_auth
The Python module OpenStack Auth provides Authentication mechanism
for the OpenStack Dashboard (Horizon).

%prep
%autosetup -p1 -n {{ pypi_name }}-{{upstream_version}}
%py_req_cleanup

# Fix manage.py shebang
sed -i 's#%{_bindir}/env python#%{_bindir}/python3#' manage.py

%build
# compile mo files before build
pushd horizon
python3 ../manage.py compilemessages
popd
pushd openstack_dashboard
python3 ../manage.py compilemessages
popd
%{py3_build}

%check
rm horizon/test/unit/hacking/test_checks.py
python3 manage.py test horizon --settings=horizon.test.settings
# TODO
# python3 manage.py test openstack_dashboard --settings=openstack_dashboard.test.settings --exclude-dir=openstack_dashboard/test/integration_tests


%install
%{py3_install}

# Move openstack_dashboard files
install -d -m 755 %{buildroot}%{http_dashboard_dir}
mv %{buildroot}%{python3_sitelib}/openstack_dashboard/ %{buildroot}%{http_dashboard_dir}
install -m 755 manage.py %{buildroot}%{http_dashboard_dir}/manage.py

# Create a local_settings.py
mv %{buildroot}%{http_dashboard_dir}/openstack_dashboard/local/local_settings.py{.example,}

# create root and static files
install -m 0755 -d %{buildroot}%{http_dashboard_dir}/static
install -m 0755 -d %{buildroot}%{http_dashboard_dir}/media
pushd %{buildroot}%{http_dashboard_dir}
PYTHONPATH=%{buildroot}%{python3_sitelib} python3 manage.py collectstatic --noinput
popd

# cleanup after manage.py run
rm -v %{buildroot}%{http_dashboard_dir}/openstack_dashboard/local/.secret_key_store
rm -v %{buildroot}%{http_dashboard_dir}/openstack_dashboard/local/*secret_key_store*

# Remove duplicate files
%if 0%{?suse_version}
%fdupes %{buildroot}%{python3_sitelib}
%fdupes %{buildroot}%{http_dashboard_dir}
%endif
rm -f %{buildroot}%{http_dashboard_dir}/openstack_dashboard/.eslintrc

install -D -m 644 %{SOURCE2} %{buildroot}%{apache_conf_dir}/openstack-dashboard.conf.sample

%files
%doc README.rst
%{http_dashboard_dir}
%attr(0750, %{apache_user}, %{apache_group}) %{http_dashboard_dir}/openstack_dashboard/local
%attr(0640, %{apache_user}, %{apache_group}) %{http_dashboard_dir}/openstack_dashboard/local/__init__.py*
%config(noreplace) %attr(0640, %{apache_user}, %{apache_group}) %{http_dashboard_dir}/openstack_dashboard/local/local_settings.py*
%attr(0770, root, %{apache_group}) %{http_dashboard_dir}/static/
%attr(0770, root, %{apache_group}) %{http_dashboard_dir}/media/
%{apache_conf_dir}/openstack-dashboard.conf.sample

%files -n python3-horizon
%license LICENSE
%{python3_sitelib}/horizon
%{python3_sitelib}/horizon-*.egg-info

%files -n python3-openstack_auth
%license LICENSE
%{python3_sitelib}/openstack_auth

%changelog
